﻿using System;
using System.Configuration;
using mojoPortal.Net;
using mojoPortal.Web;
using Resources;
using mojoPortal.Web.Framework;
using System.Collections;
using mojoPortal.Business;
using ud_gSDMS.Code_Service;
using mojoPortal.Business.WebHelpers;
using System.IO;
using Brettle.Web.NeatUpload;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace ud_gSDMS.Member
{
    public partial class FamilyRelationShip : mojoBasePage
    {
        private int pageId = -1;
        private int moduleId = -1;
        private string id;
        private SiteUser _siteUser;
        protected String cacheDependencyKey;
        DBQLNS _respository=new DBQLNS();
        
            
        void Page_Load(object sender, EventArgs e)
        {
            _siteUser = SiteUtils.GetCurrentSiteUser();
            if (_siteUser == null)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/AccessDenied.aspx");
            }

            if (!Page.IsPostBack)
            {
                PopulateLabels();
                PopulateControls();
            }
        }
        private void PopulateLabels()
        {
            leftMenuItem.CurrentSite = Request.RawUrl;
            FamilyRelationships abroad1 = new FamilyRelationships("Cha", "Đinh Quyển", "", "Xã Đức Lâm, Huyện Đức Thọ, Tỉnh Hà Tĩnh");
            FamilyRelationships abroad2 = new FamilyRelationships("Mẹ", "Phan Thị Đường", "", "Xã Đức Lâm, Huyện Đức Thọ, Tỉnh Hà Tĩnh");
            FamilyRelationships abroad3 = new FamilyRelationships("Cha vợ", "Nguyễn Viết Tiến", "", "24/31 Võ Thị Sáu, Tp. Cần Thơ");
            FamilyRelationships abroad4 = new FamilyRelationships("Mẹ vợ", "Trịnh Thị Nhài", "08/07/1963", "Kỹ sư, 58/1, Kp 1, P. Tân Thới Nhất, Q.12, Tp. HCM");
            FamilyRelationships abroad5 = new FamilyRelationships("Con", "Đinh Thanh Ngân", "09/03/1990", "Sinh Viên, 58/1, Kp 1, P. Tân Thới Nhất, Q.12, Tp. HCM");
            FamilyRelationships abroad6 = new FamilyRelationships("Con", "Đinh Duy Khiêm", "04/12/1995", "Học sinh, 58/1, Kp 1, P. Tân Thới Nhất, Q.12, Tp. HCM");
            FamilyRelationships abroad7 = new FamilyRelationships("Em", "Đinh Khắc Sơn", "", "Sĩ quan QĐNVVN, xã Đức Lâm, huyện Đức Thọ, tĩnh Hà Tĩnh");
            List<FamilyRelationships> lst = new List<FamilyRelationships>();
            lst.Add(abroad1);
            lst.Add(abroad2);
            lst.Add(abroad3);
            lst.Add(abroad4);
            lst.Add(abroad5);
            lst.Add(abroad6);
            lst.Add(abroad7);
            Session["Fr"] = lst;
        }
        private void BindData()
        {
            gvChildInfo.DataSource = Session["Fr"];
            gvChildInfo.DataBind();
        }

        private void PopulateControls()
        {
            BindData();
        }
        #region OnInit

        protected override void OnPreInit(EventArgs e)
        {
            AllowSkinOverride = true;
            base.OnPreInit(e);
            Load += Page_Load;
        }

        protected override void OnInit(EventArgs e)
        {
            LoadParams();
            LoadPanels();
            base.OnInit(e);
            SuppressPageMenu();
        }

        private void LoadParams()
        {
            pageId = WebUtils.ParseInt32FromQueryString("pageid", pageId);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", true, moduleId);
            id = WebUtils.ParseStringFromQueryString("id", id);
            cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
        }

        private void LoadPanels()
        {
            bool showLeftColumnAdmin = ConfigHelper.GetBoolProperty("ShowLeftColumnAdmin", false);
            bool showRightColumnAdmin = ConfigHelper.GetBoolProperty("ShowRightColumnAdmin", false);
            bool showTopColumnAdmin = ConfigHelper.GetBoolProperty("ShowTopColumnAdmin", false);
            bool showBottomColumnAdmin = ConfigHelper.GetBoolProperty("ShowBottomColumnAdmin", false);
            int showCenterColumnAdmin = ConfigHelper.GetIntProperty("ShowCenterColumnAdmin", 0);
            LoadSideContent(showLeftColumnAdmin, showRightColumnAdmin, showTopColumnAdmin, showBottomColumnAdmin, showCenterColumnAdmin);
        }
        #endregion

        protected void gvChildInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvChildInfo.EditIndex = e.NewEditIndex;
            BindData();
        }

        protected void gvChildInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List<FamilyRelationships> l = (List<FamilyRelationships>)Session["Fr"];
            TextBox txt_quanhe = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt1");
            TextBox txt_hoten = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt2");
            TextBox txt_ngaysinh = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt3");
            TextBox txt_lamo = (TextBox)gvChildInfo.Rows[e.RowIndex].FindControl("txt4");

            FamilyRelationships newfr = new FamilyRelationships(txt_quanhe.Text, txt_hoten.Text,txt_ngaysinh.Text,txt_lamo.Text);
            l[e.RowIndex] = newfr;
            gvChildInfo.EditIndex = -1;
            BindData();
        }

        protected void gvChildInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<FamilyRelationships> l = (List<FamilyRelationships>)Session["Fr"];
            l.RemoveAt(e.RowIndex);
            BindData();
        }
    }

    public class FamilyRelationships
    {
        public string QuanHe { get; set; }
        public string HoTen { get; set; }
        public string NgaySinh { get; set; }
        public string LamO { get; set; }
        public FamilyRelationships(string quanHe, string hoTen, string ngaySinh, string lamO)
        {
            this.QuanHe = quanHe;
            this.HoTen = hoTen;
            this.NgaySinh = ngaySinh;
            this.LamO = lamO;
        }
    }

    
}